package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.Build;
import com.hengxinguotong.zhihuichengjian.treeview.RecyclerAdapter;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by liux on 2017/3/7.
 */

public class ReplyListEnterpriseAdapter extends RecyclerAdapter<Build, ReplyListEnterpriseAdapter.EReplyViewHolder> {


    public ReplyListEnterpriseAdapter(Context context, List<Build> dataList) {
        super(context, dataList);
    }

    @Override
    public EReplyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_reply_list_enterprise, null);
        return new EReplyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(EReplyViewHolder holder, int position) {
        holder.bindData(position);
    }

    public class EReplyViewHolder extends RecyclerAdapter.BaseViewHolder<Build> {
        @BindView(R.id.construction_name)
        HXTextView constructionName;
        @BindView(R.id.state_iv)
        ImageView stateIv;
        @BindView(R.id.state_tv)
        HXTextView stateTv;
        @BindView(R.id.content)
        HXTextView content;
        @BindView(R.id.person_liable_tv)
        HXTextView personLiableTv;
        @BindView(R.id.person_tv)
        HXTextView personTv;
        @BindView(R.id.reply_date_tv)
        HXTextView replyDateTv;
        @BindView(R.id.data_tv)
        HXTextView dataTv;
        @BindView(R.id.order_no_tv)
        HXTextView orderNoTv;

        public EReplyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void bindData(int position) {
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            itemView.setLayoutParams(params);
            final Build build = dataList.get(position);
            constructionName.setText(build.getConstructionName());
            switch (build.getCorrectiveStatus()) {//任务状态1:待回复;2:待复检;3:复检不通过;4:已完成
                case 1:
                    stateTv.setText("待回复");
                    stateTv.setTextColor(context.getResources().getColor(R.color.color_1294db));
                    stateIv.setImageResource(R.mipmap.daizhenggai);
                    break;
                case 2:
                    stateTv.setText("待复检");
                    stateTv.setTextColor(context.getResources().getColor(R.color.color_978cff));
                    stateIv.setImageResource(R.mipmap.pending_review);
                    break;
                case 3:
                    stateTv.setText("复检不通过");
                    stateTv.setTextColor(context.getResources().getColor(R.color.color_ed8d70));
                    stateIv.setImageResource(R.mipmap.canceled);
                    break;
                case 4:
                    stateTv.setText("已完成");
                    stateTv.setTextColor(context.getResources().getColor(R.color.color_71e5a2));
                    stateIv.setImageResource(R.mipmap.already_confirmed);
                    break;
            }
            orderNoTv.setText(build.getOrderNo());
            content.setText(build.getItems());
            personLiableTv.setText(build.getContactName());
            personTv.setText(build.getCreateName());
            replyDateTv.setText(build.getDeadlineReplyDate());
            dataTv.setText(build.getInspectDate());
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onClickListener.onClick(build);
                }
            });
        }
    }
}
